package edu.ptu.shortlink.project.dao.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import edu.ptu.shortlink.project.dao.entity.ShortLinkDO;
import edu.ptu.shortlink.project.dto.req.ShortLinkPageReqDTO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

/**
 * @BelongsProject: shortlink
 * @BelongsPackage: edu.ptu.shortlink.project.dao.mapper
 * @Author: HYJ
 * @CreateTime: 2025-04-26  21:08
 * @Description: 短链接持久层
 * @Version: 1.0
 */
public interface ShortLinkMapper extends BaseMapper<ShortLinkDO> {
    /**
     * 增加历史访问数据
     *
     * @param gid          分组标识
     * @param fullShortUrl 短链接
     * @param totalPv      总PV
     * @param totalUv      总UV
     * @param totalUip     总IP
     */
    @Update("UPDATE " +
            "   t_link SET total_pv = total_pv + #{totalPv}, " +
            "       total_uv = total_uv + #{totalUv}, " +
            "       total_uip = total_uip + #{totalUip} " +
            "WHERE " +
            "   gid = #{gid} AND full_short_url = #{fullShortUrl}")
    void increase(
            @Param("gid") String gid,
            @Param("fullShortUrl") String fullShortUrl,
            @Param("totalPv") Integer totalPv,
            @Param("totalUv") Integer totalUv,
            @Param("totalUip") Integer totalUip);

    /**
     * 分页统计短链接
     */
    IPage<ShortLinkDO> pageLink(ShortLinkPageReqDTO shortLinkPageReqDTO);
}
